<?php

namespace Users {

    class Controller_Accounts extends \Controller_Base {

        public $secure_actions = array('index' => NULL, 'settings' => NULL, 'logout' => NULL);

        public function before()
        {
            parent::before();
        }

        public function action_index()
        {
            $name = \Input::get('name');

            if (is_null($name))
            {
                $accounts = Model_Account::find_all_by_user_id($this->user_id);
                $accounts_list = array();

                foreach ($accounts as $account)
                {
                    array_push($accounts_list, $account->as_array());
                }

                $this->template->title = 'Accounts';
                $this->template->accounts = $accounts_list;

                /*
                foreach ($accounts as $account) {
                    echo "<pre>";
                    print_r($account->username);
                    echo "</pre>";
                } */
            }
            else
            {
                $name = \Security::clean($name, array('strip_tags'));
                $options = array(
                   'where' => array(
                       array("user_id", "=", $this->user_id),
                       array("username", "=", $name)
                   ),
                   'limit' => 1
                );

                $account = Model_Account::find('first', $options);

                $this->template->title = 'Accounts';
                $this->template->accounts = $account;
            }
        }
    } // End: Controller_Accounts

}
